<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<title>后台管理系统</title>
	    <meta name="author" content="BaiYY"/>
	    <meta charset="utf-8">
	    <meta http-equiv="X-UA-Compatible" content="IE=edge">
	    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no">
	    <meta name="renderer" content="webkit">
	  	<link rel="stylesheet" type="text/css" href="__PUBLIC__/admin/css/bootstrap.min.css"/>
	    <link rel="stylesheet" type="text/css" href="__PUBLIC__/admin/css/Font/css/font-awesome.min.css"/>
	    <link rel="stylesheet" type="text/css" href="__PUBLIC__/admin/css/index.css"/>
	    <script type="text/javascript" src="__PUBLIC__/admin/js/jquery.js"></script>
	    <script type="text/javascript" src="__PUBLIC__/admin/js/bootstrap.min.js"></script>
	    <script type="text/javascript" src="__PUBLIC__/admin/js/index.js"></script>
	    <script type="text/javascript" src="__PUBLIC__/admin/js/jquery.validate.min.js"></script>
	</head>
	<body>
		
		<!--右边侧栏开始-->
		<div class="right-sidebar" style="max-width: 1200px;">
			<div class="row" style="margin:20px auto;">
		        <div class="col-md-12">
		        	<form role="form" id="pwdForm">
	                    <fieldset>
	                        <div class="form-group">
	                            <input class="form-control" placeholder="请输入原始密码" name="password" id="password" type="password"/>
	                        </div>
	                        <div class="form-group">
	                            <input class="form-control" placeholder="请输入新密码" name="new_password" id="new_password" type="password"/>
	                        </div>
	                        <div class="form-group">
	                            <input class="form-control" placeholder="请再次输入新密码" name="new_repassword" id="new_repassword" type="password"/>
	                        </div>
	                       <div class="text-center"><input type="submit" class="btn btn-primary" id="submit" value="修改"/></div>
	                    </fieldset>
	          		</form>
		        </div>
		    </div>
		</div>
		<script type="text/javascript">
		
			$("#password").blur(function(){
	        	var password = $.trim($("#password").val());
	        	$.ajax({
	        		type:"post",
	        		url:"{:U('Admin/Main/pwdCheck')}",
	        		dataType:"json",
	        		data:{"password":password},
	        		success:function(data){
	        			if(data == 'error') {
	        				alert("原始密码错误！");
	        				window.location.href="{:U('Admin/Main/modifyLn')}";
	        				return false;
	        			}
	        		}
	        	});
	        });
	        
			$.validator.setDefaults({
					submitHandler:function() {
						var password = $.trim($('#password').val());
						var new_password = $.trim($('#new_password').val());
						var new_repassword = $.trim($('#new_repassword').val());
						$.ajax({
							type:"post",
							url:"{:U('Admin/Main/InSave')}",
							dataType:"json",
							data:{'password':password,'new_password':new_password,'new_repassword':new_repassword},
							success:function(data) {
								if(data == 'success') {
		      						alert("修改成功");
		      						window.location.href="{:U('Admin/Main/modifyLn')}";
		      					}else if(data == 'error'){
		      						alert("修改失败！");
		      					}
							}
						});
					}
			});
			$().ready(function(){
				$("#pwdForm").validate({
					rules: {
						password:"required",
						new_password:"required",
						new_repassword:"required",
						password: {
							required: true,
							minlength: 6,
                            maxlength:20
						},
						new_password: {
							required: true,
					        minlength: 6,
                            maxlength:20
						},
						new_repassword: {
							required: true,
					        minlength: 6,
                            maxlength:20,
					        equalTo: "#new_password"
						},
					},
					messages:{
						password: {
							required: "原始密码不能为空",
							minlength: "密码最少6位",
                            maxlength: "密码最多20位"
						},
						new_password: {
							required: "新密码不能为空",
							minlength: "新密码最少6位",
                            maxlength: "密码最多20位"
						},
						new_repassword: {
							required: "确认密码不能为空",
							minlength: "新密码最少6位",
                            maxlength: "密码最多20位",
							equalTo: "两次输入密码不一致"
						}
					}
				})
			});
		</script>
	</body>
</html>
